import Vue from "vue";
import Router from "vue-router";
// import Home from "./views/Home.vue";
import Login from "./views/Login.vue";
import Home from "./views/Home.vue";

Vue.use(Router);

var router = new Router({
  routes: [
    { path: "/login", component: Login },
    { path: "/home", component: Home }
  ]
});

// 路由守卫
router.beforeEach(function(to, from, next) {
  // 获取token
  var token = window.sessionStorage.getItem("token");

  if (token === null && toString.path !== "/login") {
    return next("/login");
  }
  next();
});

export default router;
